﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AAB;
namespace Esa
{
    public class BypassAudioSet : MonoBehaviour
    {
        public string postFix = ".wav";
        public SourceWrapper[] sources;
        [Button]
        void SetDontPlayAwake()
        {            
            foreach (var src in GetComponentsInChildren<SourceWrapper>())
            {
                src.Reset();
            }
        }
        void Awake()
        {
            SetPath();
        }
        public void Play(int i)
        {
            sources[i].Play();
        }
        [Button]
        void SetPath()
        {
            sources = GetComponentsInChildren<SourceWrapper>();
            foreach (var wp in sources)
            {
                var src = wp.GetComponent<BypassAudioSource>();
                src.m_bypassAudioManager = BypassAudioManager.I;
                var clip = src.GetComponent<AudioSource>().clip;
                if (clip != null) src.m_audioFile = gameObject.name + "/" + clip.name + postFix;
            }
        }
    }
}